package kr.ac.ml.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import kr.ac.ml.action.BadAction;
import kr.ac.ml.action.GoodAction;
import kr.ac.ml.action.LoginAction;
import kr.ac.ml.action.LoginViewAction;
import kr.ac.ml.action.MeAction;
import kr.ac.ml.action.RefreshAction;
import kr.ac.ml.action.ReplyAction;
import kr.ac.ml.action.ReplyListAction;
import kr.ac.ml.action.MainAction;
import kr.ac.ml.action.WriteAction;
import kr.ac.ml.action.WriteMeAction;
import kr.ac.ml.mvc.Action;




@WebServlet("/main")
public class mainserlvet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub		
		doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
String a = request.getParameter("a");
		
		Action action = null;
		
		System.out.println("mainservlet");
		System.out.println("a : " + a);
		
		
		if("write".equals(a)){
			String content = request.getParameter("content");
			System.out.println("content : " + content );
			action = new WriteAction();
		}else if("replyList".equals(a)){
			action = new ReplyListAction();
		}else if("reply".equals(a)){
			action = new ReplyAction();
		}else if("main".equals(a)){
			action = new MainAction();
		}else if("login".equals(a)){
			action = new LoginAction();
		}else if("good".equals(a)){
			action = new GoodAction();
		}else if("bad".equals(a)){
			action = new BadAction();
		}else if("me".equals(a)){
			action = new MeAction();
		}else if("writeme".equals(a)){
			action = new WriteMeAction();
		}else if("refresh".equals(a)){
			action = new RefreshAction();
		}else{
			action = new LoginViewAction();
			
		}

		
		action.execute(request, response);
		
		System.out.println(request.getAttribute("json"));
		response.setContentType("text/html; charset=utf-8");
		PrintWriter out = response.getWriter();
		out.print(request.getAttribute("json"));

		
	}

}
